#include "main.h"
#include "ParseType.h"
#include "ParseTS_Head.h"

TS_Package_Head ParseTS_PackageHead(TS_Package_Head TS_PackageHead, unsigned char PackageHead_data[4])
{
	TS_PackageHead.sync_byte = PackageHead_data[0];
	TS_PackageHead.transport_error_indicator = PackageHead_data[1] >> 7;
	TS_PackageHead.payload_unit_start_indicator = (PackageHead_data[1] >> 6) & 0x01;
	TS_PackageHead.transport_priority = (PackageHead_data[1] >> 5) & 0x01;
	TS_PackageHead.PID = ((PackageHead_data[1] & 0x1F) << 8) | PackageHead_data[2];
	TS_PackageHead.transport_scrambling_control = PackageHead_data[3] >> 6;
	TS_PackageHead.adaptation_field_control = (PackageHead_data[3] >> 4) & 0x03;
	TS_PackageHead.continuity_counter = PackageHead_data[3] & 0x0f;


	// printf("syn_byte = %x\n",TS_PackageHead.sync_byte);
	// printf("transport_error_indicator = %x\n",TS_PackageHead.transport_error_indicator);
	// printf("payload_unit_start_indicator = %x\n",TS_PackageHead.payload_unit_start_indicator);
	// printf("transport_priority = %x\n",TS_PackageHead.transport_priority);
	// printf("PID = %x\n",TS_PackageHead.PID);
	// printf("transport_scrambling_control = %x\n",TS_PackageHead.transport_scrambling_control);
	// printf("adaptation_field_control = %x\n",TS_PackageHead.adaptation_field_control);
	// printf("continuity_counter = %x\n",TS_PackageHead.continuity_counter);

	// printf("syn_byte = %x\n",TS_PackageHead.sync_byte);
	// printf("PID = %x\n",TS_PackageHead.PID);

    return TS_PackageHead;
}


TS_Package_Head ParseTS_Type()
{
    unsigned char PackageHead_data[4] = {0};
	TS_Package_Head TS_PackageHead = {0};

	memcpy(PackageHead_data, TSdata, 4);

	TS_PackageHead = ParseTS_PackageHead(TS_PackageHead, PackageHead_data);

	return TS_PackageHead;
}

 